package cn.tedu.ivos.user.service.impl;

import cn.tedu.ivos.base.exception.ServiceException;
import cn.tedu.ivos.base.response.StatusCode;
import cn.tedu.ivos.user.mapper.UserMapper;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.vo.UserVo;
import cn.tedu.ivos.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public UserVo login(UserLoginParam userLoginParam) {
        log.debug("用户登录业务，参数：{}",userLoginParam);
//        根据用户名去库里查询该用户是否存在
        UserVo userVo =userMapper.selectByUsername(userLoginParam.getUsername());
        log.debug("查询结果：{}",userVo);
        if(userVo==null){
            log.debug("用户不存在");
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if(!userVo.getPassword().equals(userLoginParam.getPassword())){
            log.debug("密码错误");
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        return userVo;
    }
}
